package com.zhiyou.controller;

import com.zhiyou.bean.Admin;
import com.zhiyou.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @RequestMapping("/login")
    public String login(Admin admin, HttpSession session){
        Admin adm = adminService.getAdminByNameAndPassword(admin);
        session.setAttribute("admin",admin);
        if(adm == null){
            session.setAttribute("msg","账号或密码错误");
            return "redirect:admin_login.jsp";
        }
        return "redirect:index.jsp";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:admin_login.jsp";
    }

}
